﻿--|--------------------------------------------------------------------------------
--| [InsertPerson] - Insert Procedure Script for Game
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[InsertPerson]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[InsertPerson]
GO

CREATE PROCEDURE [dbo].[InsertPerson]
(
	@ID int output, 
	@Name nvarchar(50), 
	@Description nvarchar(50), 
	--@Photo int, 
	@MaxSendingPause int,
	@FullName nvarchar(250),
	@BirthDate nvarchar(50),
	@TeamPhone nvarchar(50),
	@OtherPhones nvarchar(50),
	@ICQ nvarchar(50),
	@Skype nvarchar(50),
	@OtherIMs nvarchar(50),
	@Radio nvarchar(50),
	@Tracker nvarchar(50),
	@OtherDevices nvarchar(250))
AS
	SET NOCOUNT ON

DECLARE @TeamID int
SELECT TOP 1  @TeamID = ID FROM Team
INSERT INTO  dbo.Entity (Name, Description, TeamID, EntityTypeID, MaxSendingPause)
VALUES (@Name, @Description, @TeamID, 1, @MaxSendingPause)

SELECT @ID = @@IDENTITY

INSERT INTO dbo.EntityAttribute (EntityID, EntityAttributeTypeID, Value)

		  SELECT @ID, 'FNAME', @FullName 
UNION ALL SELECT @ID, 'BIRTH', CONVERT(nvarchar,@BirthDate)
UNION ALL SELECT @ID, 'TPHONE', @TeamPhone
UNION ALL SELECT @ID, 'OPHONES', @OtherPhones
UNION ALL SELECT @ID, 'ICQ', @ICQ
UNION ALL SELECT @ID, 'SKYPE', @Skype
UNION ALL SELECT @ID, 'IM', @OtherIMs
UNION ALL SELECT @ID, 'TRAN', @Radio
UNION ALL SELECT @ID, 'TRACK', @Tracker
UNION ALL SELECT @ID, 'DEVS', @OtherDevices
GO
